<?php

include_once('../@base/database.php');

$action = $_GET["action"];

$result = '';

if ($action == 'REBUILD_violationsrectifying') {
    $sql = "DROP TABLE oprec_rectify_record";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
    $sql_file = file_get_contents('oprec_rectify_record.sql');
    $sql_array = explode(';', $sql_file);
    $result .=  var_export(exec_sql_array($sql_array), true);
    $result .=  "\n\n";
} else if ($action == 'TRUNCATE_violationsrectifying') {
    $sql = "TRUNCATE TABLE oprec_rectify_record";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
} else if ($action == 'REBUILD_security_data') {
    $sql = "DROP TABLE oprec_security_data";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
    $sql_file = file_get_contents('oprec_security_data.sql');
    $sql_array = explode(';', $sql_file);
    $result .=  var_export(exec_sql_array($sql_array), true);
    $result .=  "\n\n";
} else if ($action == 'TRUNCATE_security_data') {
    $sql = "TRUNCATE TABLE oprec_security_data";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
}else if ($action == 'REBUILD_violations_rectifying_item') {
    $sql = "DROP TABLE oprec_security_data";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
    $sql_file = file_get_contents('oprec_rectify_items.sql');
    $sql_array = explode(';', $sql_file);
    $result .=  var_export(exec_sql_array($sql_array), true);
    $result .=  "\n\n";
} else if ($action == 'TRUNCATE_violations_rectifying_item') {
    $sql = "TRUNCATE TABLE oprec_rectify_items";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
}else if ($action == 'REBUILD_oprec_inspect_items') {
    $sql = "DROP TABLE oprec_inspect_items";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
    $sql_file = file_get_contents('oprec_inspect_items.sql');
    $sql_array = explode(';', $sql_file);
    $result .=  var_export(exec_sql_array($sql_array), true);
    $result .=  "\n\n";
} else if ($action == 'TRUNCATE_oprec_inspect_items') {
    $sql = "TRUNCATE TABLE oprec_inspect_items";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
}else if ($action == 'REBUILD_oprec_inspect_record') {
    $sql = "DROP TABLE oprec_inspect_record";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
    $sql_file = file_get_contents('oprec_inspect_record.sql');
    $sql_array = explode(';', $sql_file);
    $result .=  var_export(exec_sql_array($sql_array), true);
    $result .=  "\n\n";
} else if ($action == 'TRUNCATE_oprec_inspect_record') {
    $sql = "TRUNCATE TABLE oprec_inspect_record";
    $result .= var_export(exec_sql($sql), true);
    $result .=  "\n\n";
}else if ($action == 'REBUILD_oprec_state') {
  $sql = "DROP TABLE oprec_state";
  $result .= var_export(exec_sql($sql), true);
  $result .=  "\n\n";
  $sql_file = file_get_contents('oprec_state.sql');
  $sql_array = explode(';', $sql_file);
  $result .=  var_export(exec_sql_array($sql_array), true);
  $result .=  "\n\n";
} else if ($action == 'TRUNCATE_oprec_state') {
  $sql = "TRUNCATE TABLE oprec_state";
  $result .= var_export(exec_sql($sql), true);
  $result .=  "\n\n";
}

?>

<html>

<head>
    <meta charset="utf-8">
    <title>SQL_EXEC</title>
</head>

<body>
    <h1>ACTIONS</h1>
    <p>
        <b>oprec_security_data:</b>
        <a href="index.php?action=REBUILD_security_data">REBUILD</a>
        <a href="index.php?action=TRUNCATE_security_data">TRUNCATE</a>
    </p>
    <p>
        <b>oprec_rectify_record:</b>
        <a href="index.php?action=REBUILD_violationsrectifying">REBUILD</a>
        <a href="index.php?action=TRUNCATE_violationsrectifying">TRUNCATE</a>
    </p>
    <p>
        <b>oprec_rectify_items:</b>
        <a href="index.php?action=REBUILD_violations_rectifying_item">REBUILD</a>
        <a href="index.php?action=TRUNCATE_violations_rectifying_item">TRUNCATE</a>
    </p>
    <p>
        <b>oprec_inspect_items:</b>
        <a href="index.php?action=REBUILD_oprec_inspect_items">REBUILD</a>
        <a href="index.php?action=TRUNCATE_oprec_inspect_items">TRUNCATE</a>
    </p>
    <p>
        <b>oprec_inspect_record:</b>
        <a href="index.php?action=REBUILD_oprec_inspect_record">REBUILD</a>
        <a href="index.php?action=TRUNCATE_oprec_inspect_record">TRUNCATE</a>
    </p>
    <p>
        <b>oprec_oprec_state:</b>
        <a href="index.php?action=REBUILD_oprec_state">REBUILD</a>
        <a href="index.php?action=TRUNCATE_oprec_state">TRUNCATE</a>
    </p>
    <?php if (!$action) die; ?>
    <br />
    <h1>EXPORTS</h1>
    <pre>
        <?php echo $result ?>
    </pre>
</body>

</html>